/**
 * 
 */
package tp.pr5.gui;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;

import tp.pr5.Constants;
import tp.pr5.PlaceInfo;

/**
 * @author VICTOR
 *
 */
public class PlaceCell extends JButton {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private PlaceInfo place;
	private NavigationPanel navPanel;
	
	/**
	 * Constructor of PlaceCell
	 * @param navigationPanel
	 */
	public PlaceCell(NavigationPanel navigationPanel) {
		this.navPanel = navigationPanel;
		this.addActionListener(new placeCellListener());
	}
	
	public void arriveAt(PlaceInfo arrivalPlace)
	{
		this.place = arrivalPlace;
		this.setText(place.getName());
		this.setBackground(Color.GREEN);
	}
	
	/**
	 * set gray color for button
	 */
	public void left()
	{
		this.setBackground(Color.GRAY);
	}
	
	class placeCellListener implements ActionListener
	{
        public void actionPerformed(ActionEvent e)
        {
        	if (place != null)
        		navPanel.showCurrentPlace(place.toString() + Constants.LINE_SEPARATOR);
        }
    }

}
